<?php

defined( 'IN_DICE' ) or die( 'Access Error!' );

include_once( DIR_MDL . 'platform/platform.php' );
include_once( DIR_MDL . 'platform/class.fiveone.php' );

class fiveone implements platform {
	
	/**
	 * @var OpenApp_51
	 */
	public $op;
	public $pfid;
	public $apiid;
	public $apikey;
	public $apisecret;
	public $apiurl;
	
	public function __construct() {
		$this->pfid = all::$cfg['fiveone_pfid'];
		$this->apiid = all::$cfg['fiveone_apiid'];
		$this->apikey = all::$cfg['fiveone_apikey'];
		$this->apisecret = all::$cfg['fiveone_apisecret'];
		$this->apiurl = all::$cfg['fiveone_apiurl'];
		$this->op = new OpenApp_51( $this->apikey, $this->apisecret );
	}
	
	/**
	 * 获取当前登录用户的平台ID.字符串型,没有获取到则为空字符串
	 */
	public function getUserId() {
		$aInfo = $this->op->api_client->users_getLoggedInUser(); 
		$uid = (string)$aInfo[0]['uid'];
		return $uid ? $uid : '';
	}
	public function getUserInfo( $uid ) { //获取五一的用户资料
		if( !strlen( $uid ) ) {
			return array();
		}
		
		$params = array (
	    			"uids"	=> array( $uid),
	    			"fields"=> array('uid','nickname','facesmall','face','facebig','sex','prov','city','hprov','hcity','vip','homeurl','isconfirm',),
					);
		$uinfo = $this->op->api_client->users_getInfo($params['uids'], $params['fields']);
		
		$uinfo = $uinfo[0]; //二维数组
		
		return ( strcmp($uid, $uinfo['uid']) !== 0 ) ? array() : array( //错误则返回空数组,否则严格返回以下格式
																	'puid' => $uinfo['uid'],
																	'uname' => $uinfo['nickname'] ? $uinfo['nickname'] : $uinfo['uid'],
																	'headurl' => $uinfo['face'],
																	'sex' => $uinfo['sex'],
																	'psuid' => '',
																	'upage' => 'http://home.51.com/' . $uinfo['uid'],
																	'usid' => 0, //用户的子ID,用于同城或者本站
																	'pfid' => all::$cfg['fiveone_pfid'],
																	);
	}
	public function getAllFriends(){
		
	}
	public function getAppFriends(){
		
	}
	
	/**
	 * 应用授权，用户是否添加此应用或已登录
	 */
	public function isAdded() {
		
	}
	public function getSiteInfo() {
		
	}
	public function sendNotice() {
		
	}
	public function sendFeed( $aFields ) {
		
	}
	public function setProfile() {
		
	}
	public function setKey( $key ) {
		$this->op->session_key = $key;
	}
}
